package com.tem.finance.service.impl;

import com.api.manage.pojo.finance.BillListBean;
import com.tem.finance.entity.Bill;
import com.api.manage.pojo.finance.BillBean;
import com.tem.finance.entity.BillOffline;
import com.tem.finance.entity.BillOnline;
import com.tem.finance.mapper.BillMapper;
import com.tem.finance.service.IBillOfflineService;
import com.tem.finance.service.IBillOnlineService;
import com.tem.finance.service.IBillService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 资金流-业务关联处理 服务实现类
 * </p>
 *
 * @author 陈辉
 * @since 2023-11-06
 */
@Service
public class BillServiceImpl extends ServiceImpl<BillMapper, Bill> implements IBillService {
    @Autowired
    private IBillOnlineService billOnlineService;
    @Autowired
    private IBillOfflineService billOfflineService;

    public BillListBean getAll(Bill bill){
        BillListBean bean = new BillListBean();
        BeanUtils.copyProperties(bill,bean);
        bean.toInit();
        if(bill.getPaymentHistoryId()==null || bill.getPaymentHistoryId().longValue()<1){
            BillOffline billOffline = billOfflineService.getById(bill.getBillId());
            if(billOffline!=null)BeanUtils.copyProperties(billOffline,bean);
        }else{
            BillOnline billOnline = billOnlineService.getById(bill.getBillId());
            if(billOnline!=null)BeanUtils.copyProperties(billOnline,bean);
        }
        return bean;
    }
}
